/*
-----------------------------------------------------------------------------
Filename:    Dredd.h
Author: Michael Sebright
-----------------------------------------------------------------------------
Defines the main character Dredd
*/

#ifndef __Dredd_H__
#define __Dredd_H__

#include "Ogre.h"
#include "OIS.h"
#include "Bullet.h"

using namespace Ogre;

#define CHAR_HEIGHT 5          // height of character's center of mass above ground
#define CAM_HEIGHT 2		   // set how high the camer should be
#define NUM_ANIMS 15           // number of animations the character has
#define NUM_LOWER_ANIMS 7	   // number of lower animations the character has
#define RUN_SPEED 17           // character running speed in units per second
#define ANIM_FADE_SPEED 7.5f   // animation crossfade speed in % of full weight per second
#define NUM_ACTIVE_BULLETS 20  // set the amount of bullets dredd can be shooting at one time
#define SHOT_PER_SECOND 10.0f  // set how fast dredd can shoot
 

class Dredd {
private:

	// all the animations our character has, and a null ID
	enum AnimID {
		LEGS_IDLE,
		LEGS_IDLECR,
		LEGS_RUN,
		LEGS_TURN,
		LEGS_WALK,
		LEGS_WALKCR,
		LEGS_BACK,
		TORSO_GESTURE,
		TORSO_ATTACK,
		TORSO_ATTACK2,
		TORSO_DROP,
		TORSO_RAISE,
		TORSO_STAND,
		TORSO_STAND2,
		BOTH_DEATH1,
		ANIM_NONE
	};


	SceneNode* mBodyNode;
	SceneNode* mLowerNode;
	SceneNode* mUpperNode;
	SceneNode* mHeadNode;
	SceneNode* mGunNode;

	Entity* mBodyEnt;
	Entity* mLowerEnt;
	Entity* mUpperEnt;
	Entity* mHeadEnt;
	Entity* mGunEnt;

	Vector3 mKeyDirection;      // player's local intended direction based on WASD keys
	Vector3 mGoalDirection;     // actual intended direction in world-space

	AnimationState* mAnims[NUM_ANIMS + 1];    // master animation list
	bool mFadingIn[NUM_ANIMS + 1];            // which animations are fading in
	bool mFadingOut[NUM_ANIMS + 1];           // which animations are fading out
	AnimID mLowerAnimID;                      // current base (full- or lower-body) animation
	AnimID mUpperAnimID;                      // current top (upper-body) animation

	SceneNode* mCameraPivot;
	SceneNode* mCameraGoal;
	SceneNode* mCameraNode;
	Real mPivotPitch;

	Real mTimer;                // general timer to see how long animations have been playing 
	Real shotTimer;				// timer to mange shots per second

	Bullet bullets[NUM_ACTIVE_BULLETS]; // List of bullet objects for dredd
	bool attacking;						// Flag to see if mouse is being held down
	int ammoIndex;						// Index for bullet array

	int lives; // lives dredd has



	void setupBody(SceneManager* sceneMgr);
	void updateBody(Real deltaTime);
	void setupWeapons(SceneManager* sceneMgr);
	void updateWeapons(Real deltaTime);
	void setupAnimations();
	void updateAnimations(Real deltaTime);
	void fadeAnimations(Real deltaTime);
	void setupCamera(Camera* cam);
	void updateCamera(Real deltaTime);
	void setLowerAnimation(AnimID id, bool reset = false);
	void setUpperAnimation(AnimID id, bool reset = false);
	
public: 
	Dredd(Ogre::Camera* cam); 
	void keyUp(const OIS::KeyEvent& evt);
	void keyDown(const OIS::KeyEvent& evt);
	void mouseMoved(const OIS::MouseEvent& evt);
	void mouseDown(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
	void mouseUp(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
	void addTime(Real deltaTime);
	void setPosition(Vector3 positon, Quaternion orientaion);
	void setLives(int lives);
	bool die();
	std::list<Bullet *> activeBullets();
	Vector3 getLocation();
	int getLives();
};

#endif